unit CadVeiculoParado2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Template, AppEvnts, DB, Buttons, ComCtrls, ToolWin, StdCtrls,
  Mask, DBCtrls, JvExControls, JvComponent, JvDBLookup, Menus;

type
  TFormCadVeiculoParado2 = class(TFormTemplate)
    Label1: TLabel;
    DBEdit1: TDBEdit;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    Label3: TLabel;
    DBEdit3: TDBEdit;
    Label4: TLabel;
    DBEdit4: TDBEdit;
    Label5: TLabel;
    DBEdit5: TDBEdit;
    Label6: TLabel;
    DBEdit6: TDBEdit;
    Label7: TLabel;
    DBEdit7: TDBEdit;
    SpeedButton5: TSpeedButton;
    JvDBLookupComboLocal: TJvDBLookupCombo;
    SpeedButton1: TSpeedButton;
    JvDBLookupComboCidade: TJvDBLookupCombo;
    SpeedButton3: TSpeedButton;
    JvDBLookupComboOcorrencia: TJvDBLookupCombo;
    SpeedButton2: TSpeedButton;
    JvDBLookupComboVeiculo: TJvDBLookupCombo;
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure btnAbrirClick(Sender: TObject);
    procedure btnPesquisarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    CodVeiculo : String;
    AltIns : Char;
  public
    Procedure Mostrar (CodVeiculo: String; AltIns : Char);
    { Public declarations }
  end;

var
  FormCadVeiculoParado2: TFormCadVeiculoParado2;

implementation

uses DM, DMS, Principal, Abrir, Pesquisa, Geral;

{$R *.dfm}

procedure TFormCadVeiculoParado2.SpeedButton5Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Local1 , JvDBLookupComboLocal );
end;

procedure TFormCadVeiculoParado2.SpeedButton3Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Ocorrencia1 , JvDBLookupComboOcorrencia );
end;

procedure TFormCadVeiculoParado2.SpeedButton1Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Cidade1 , JvDBLookupComboCidade );
end;

procedure TFormCadVeiculoParado2.SpeedButton2Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Veiculo1 , JvDBLookupComboVeiculo );
end;

procedure TFormCadVeiculoParado2.btnAbrirClick(Sender: TObject);
begin
  inherited;
    FormAbrir.mostrar(DMPrinc.QueryVeiculoParado,'CODVEICULOPARADO');
    FreeAndNil(FormAbrir);
end;

procedure TFormCadVeiculoParado2.btnPesquisarClick(Sender: TObject);
var
     RespFiltro: String;
     RespCombo : String;
begin
  inherited;
    RespFiltro :=  MetodosGer.OpenFiltro('VEICULO;', 1, false);
    if RespFiltro <> '-1' then
    begin
        if GetFiltro(RespFiltro, 3) > 0 then
        begin
            dsPrincipal.DataSet.Filtered := False;
            dsPrincipal.DataSet.Filter := 'codveiculo ='+inttostr(GetFiltro(RespFiltro, 3));
            dsPrincipal.DataSet.Filtered := True;
        end;
    end;
    FormPesquisa.Mostrar('Pesquisa' , 'codveiculoparado' , Dmprinc.QueryVeiculoParado ,
                        'DataStart;DataStart;DataStop;DataStop;Codigo;CodVeiculoParado;');
    FreeAndNil(FormPesquisa);
    dsPrincipal.DataSet.Filtered := False;
end;

procedure TFormCadVeiculoParado2.Mostrar(CodVeiculo : String;AltIns : Char);
begin
    Self.AltIns := AltIns;
    self.CodVeiculo := codveiculo;
    showmodal;
end;

procedure TFormCadVeiculoParado2.FormShow(Sender: TObject);
var CodParado : String;
begin
    SetaDataset(dsPrincipal,DMprinc.QueryVeiculoParado);
  inherited;
    if CodVeiculo <> '' then
    begin
        if AltIns = 'I' then
        begin
            dsPrincipal.DataSet.open;
            dsPrincipal.DataSet.Insert;
            dsPrincipal.DataSet.FieldByName('codveiculo').AsString := codveiculo;
        end
        else
        begin
            Where.Clear;
            Where.Add('codveiculo = '+ CodVeiculo);
            Where.Add('datastart is null');
            Where.Add(' AND ');
            CodParado := GetCampoQuery('veiculoparado','codveiculoparado',Where);
            where.Clear;
            dsPrincipal.DataSet.Open;
            dsPrincipal.DataSet.Locate('codveiculoparado',CodParado,[]);
            dsPrincipal.Edit;
            DBEdit7.SetFocus;
        end;
    end;
end;

procedure TFormCadVeiculoParado2.FormCreate(Sender: TObject);
begin
  inherited;
    CodVeiculo := '';
end;

end.
